<template>
  <div id="app">
    <transition :name="transitionName">
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
    </transition>
  </div>
</template>
<script>
export default {
  name: 'app',
  data () {
    return {
      transitionName: ''
    }
  },
  mounted () {
    // this.$eventBus.$on('onPushEvent', () => {
    //   this.transitionName = 'slide-left'
    // })
    // this.$eventBus.$on('onBackEvent', () => {
    //   this.transitionName = 'slide-right'
    // })
  },
  watch: {
    '$route' (newPath, oldPath) {
      if (oldPath.fullPath === '/') return
      const { type } = newPath.query
      if (type === 'push') {
        this.transitionName = 'slide-left'
      } else if (type === 'normal') {
        this.transitionName = 'slide-bottom'
      } else {
        this.transitionName = 'slide-right'
      }
    }
  }
}
</script>
<style lang = "scss" scoped>
.slide-bottom-leave-active,
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  transition: all 200ms linear 0s;
  position: absolute;
  width: 100%;
}
.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%,0,0);
}
.slide-left-leave-to {
  opacity: 0;
  transform: translate3d(-100%,0,0);
}
.slide-right-leave-to {
  opacity: 0;
  transform: translate3d(100%,0,0);
}
.slide-right-enter {
  transform: translate3d(-100%,0,0);
}
.slide-bottom-leave-to,.slde-bottom-enter {
  transform: translate3d(0,100%,0);
  opacity: 0;
}
</style>
